<?php
namespace Admin\Controller;
class OptionsController extends CommonController{
	
	/**
	* 设置页面
	*/
	public function index(){
		$this->display();
	}

	/**
	* 邮件配置
	*/
	public function email(){
		$this->display();
	}

	/**
	* 重新加载配置
	*/
	public function load_options(){
		$m = M('Options');
		$datas = $m->select();
		for($i = 0 ; $i < count($datas) ; $i++){
			$group = $datas[$i]['group'];
			$key = $datas[$i]['option_name'];
			$val = $datas[$i]['option_value'];
			F('Options/option_'.$group.'_'.$key,$val);
		}
	}

	/**
	* 编辑option
	*/
	public function edit_post(){
		if(IS_POST){
			$m = M('Options');
			$group = $data['group'] = $_POST['group'];
			$map['group'] = $group;
			foreach($_POST['options'] as $key=>$val){
			
				$map['option_name'] = $key;
				$data['option_name'] = $key;
				$data['option_value'] = $val;
			
				
				if($m->where($map) -> find()){
					
					$m->where($map)->save($data);
				}else{
					
					
					$m->add($data);
					
				}
				//更新缓存
				F('Options/option_'.$group.'_'.$key,$val);
			}
			$this->success('success');
		}
	}
}